package com.zirenx.sys.controller;

import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;
import com.zirenx.annotation.RouteMapping;
import com.zirenx.common.controller.BaseController;
import com.zirenx.common.controller.IController;
import com.zirenx.sys.model.SysFile;
import com.zirenx.sys.model.SysRole;
import com.zirenx.utils.LogUtils;
import com.zirenx.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;

import java.util.List;

@RouteMapping("/sys/file")
public class SysFileController extends BaseController implements IController {

    @RequiresPermissions("sys:file:index")
    @Override
    public void index() {

    }

    @Override
    public void add() {

    }

    @Override
    public void save() {

    }

    @Override
    public void edit() {

    }

    @Override
    public void update() {

    }

    @Override
    public void remove() {

    }

    @Override
    public void dataAjax() {
        R r = R.ok();
        try {
            SysFile bean = getBean(SysFile.class,"bean");

            SqlPara sqlPara = new SqlPara();
            sqlPara.setSql("select * from "+bean.getTableName()+" bean order by bean.id desc");

            Page<SysFile> p = bean.paginate(getPageNumber(), getPageSize(), sqlPara);
            List<SysFile> list = p.getList();

            r.put("rows", list);
            r.put("total", p.getTotalRow());
        } catch (Exception e) {
            LogUtils.error(this.getClass(),e);
            r = R.error();
        }
        renderJson(r);
    }

    @Override
    public void batchRemove() {

    }
}
